package com.caseeye.model

import com.caseeye.util.DateUtil
import java.util.Date
import java.sql.Timestamp
import com.caseeye.repository.UserRepository
import org.springframework.beans.factory.annotation.Required
import javax.annotation.Resource
import com.caseeye.model.annotation.IdField
import scala.reflect.BeanProperty
import com.caseeye.base.Versioning
import com.caseeye.base.Entity

class User extends Entity with Versioning {

    @IdField
    @BeanProperty
    var userId : String = null

    @BeanProperty
    var loginId : String = null

    @BeanProperty
    var userName : String = null

    @BeanProperty
    var password : String = null

    @BeanProperty
    var lastLoginDate : Date = null

    @Required
    @Resource
    var userRepository : UserRepository = null

    def setUserRepository(userRepository : UserRepository) : Unit = this.userRepository = userRepository

    def touchLoginDate() : Unit = this.lastLoginDate = DateUtil.now

    def save() : Unit = userRepository.save(this)

}